unit uERP_Controller;

interface

uses uERP_Controller_Usuario, uERP_Controller_Contador;

type
  TController = class

    {$REGION '<< Private >>'}

      private

      {$REGION '<< Atributes >>'}

        private class var _Instance: TController;

        var _ControllerUsuario: TControllerUsuario;
        var _ControllerContador: TControllerContador;

      {$ENDREGION}

    {$ENDREGION}

    {$REGION '<< Public >>'}

      public

        {$REGION '<< Methods >>'}

          class function GetInstance(): TController;
          class procedure FreeInstance();

          function GetControllerUsuario(): TControllerUsuario;
          function GetControllerContador(): TControllerContador;

        {$ENDREGION}

    {$ENDREGION}

  end;

implementation

uses
  SysUtils;

{$REGION '<< TController >>'}

class procedure TController.FreeInstance;
begin
  if Assigned(_Instance)
    then FreeAndNil(_Instance);
end;

function TController.GetControllerContador: TControllerContador;
begin
  if not Assigned(_ControllerContador)
    then _ControllerContador := TControllerContador.Create();
  Result := _ControllerContador;
end;

function TController.GetControllerUsuario: TControllerUsuario;
begin
  if not Assigned(_ControllerUsuario)
    then _ControllerUsuario := TControllerUsuario.Create();
  Result := _ControllerUsuario;
end;

class function TController.GetInstance: TController;
begin
  if not Assigned(_Instance)
    then _Instance := inherited Create as Self;

  Result := _Instance;
end;

{$ENDREGION}

initialization

finalization
  TController.GetInstance().FreeInstance();

end.
